<?php
class OrderTaskService
{

    /*
    * 获取实时正在项目列表
    *
    */
    public static function getWorkingProjects($worker_id,$day,$today)
    {
        //获取列表
        $searchsql = Util::initSearchSql();

        //设置状态

        $searchsql = Util::getSerarchStrAdd($searchsql,"worker_id",$worker_id);
        $searchsql = Util::getSerarchStrAdd($searchsql,"status",MsgConst::ORDER_STATUS_WORKING);

        //排序
        $searchsql = $searchsql . " order by create_time  asc";
        //获取list
        $list = OrderList::model()->findAll($searchsql);

        $returnlist = array();

        for($i=0;$i<count($list);$i++)
        {
            $order = $list[$i];




            //如果是当天的

            if($day == $today)
            {
                if(OrderTaskService::hasTaskinDay($order->worker_id,$order->order_id,$day) == true)
                    $order->task_day_id = MsgConst::TASK_INFO_HAS;
                else
                    $order->task_day_id = MsgConst::TASK_INFO_EMPTY;

                array_push($returnlist,$order);

            }

            //如果是未来的
            if($day>$today)
            {
                //是否过了结束时间
                $endday = DateUtil::getDayByDatetime($order->end_day);

                if($day>$endday)
                    $order->task_day_id = MsgConst::TASK_INFO_EMPTY;
                else
                {
                    $order->task_day_id = MsgConst::TASK_INFO_LATER;
                    array_push($returnlist,$order);
                }



            }





        }

        return $returnlist;
    }


    /*
    * 获取历史某一天的有任务的项目列表
    *
    */
    public static function getProjectsWithTaskByDay($worker_id,$day)
    {
        //获取列表
        $searchsql = Util::initSearchSql();

        //设置状态

        $searchsql = Util::getSerarchStrAdd($searchsql,"worker_id",$worker_id);
        $searchsql = Util::getSerarchStrAdd($searchsql,"work_day",$day);

        //排序
        $searchsql = $searchsql . " order by create_time  asc";
        //获取list

        $tasklist = WorkerTasks::model()->findAll($searchsql);


        //list

        $projlist = array();


        $l=count($tasklist);
        for($i=0;$i<$l;$i++)
        {
            $task = $tasklist[$i];
            $order_id =$task->order_id;

            $order = OrderList::model()->findByPK($order_id);

             Util::checkExistAndNotDelete($order);

                $order->task_day_id = MsgConst::TASK_INFO_HAS;

                array_push($projlist,$order);





        }



        return $projlist;
    }


    /*
    *某一天 某工人在订单是否有任务提交
    *
    */
    public static function hasTaskinDay($worker_id,$order_id,$day)
    {
        //获取列表
        $searchsql = Util::initSearchSql();

        //设置状态

        $searchsql = Util::getSerarchStrAdd($searchsql,"worker_id",$worker_id);
        $searchsql = Util::getSerarchStrAdd($searchsql,"work_day",$day);
        $searchsql = Util::getSerarchStrAdd($searchsql,"order_id",$order_id);

        $totalcount = WorkerTasks::model()->count($searchsql);

        if($totalcount==0)
            return false;

        return true;



    }












}


?>